<template>
	<view style="padding: 30rpx;">
		<view class="box">
			<view class="">
				消费总额
			</view>
			<view class="" style="font-weight: 600;font-size: 50rpx;margin-top: 12rpx;">
				{{totalCostPrice}}
			</view>
		</view>
		<view class="items">
			<view class="item" v-for="(item,index) in list" :key="index">
				<view class="img-box">
					<image src="../../static/my/icon.png" mode=""></image>

				</view>
				<view class=""
					style="flex: 1;height: 90rpx;display: flex;flex-direction: column;justify-content: space-between;">
					<view class="" style="font-size: 30rpx;">
						{{item.memo}}
					</view>
					<view class="" style="color: #616161;">
						{{formatTimestamp(item.createtime)}}
					</view>
				</view>
				<view class="" style="color: #FF4D30;font-weight: 600;font-size: 32rpx;">
					-{{item.money}}
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		userMoneyLog
	} from "@/request/api/tiezi.js"
	export default {
		data() {
			return {
				list: [],
				totalCostPrice: 0
			}
		},
		onShow() {
			userMoneyLog({
				pageSize: 999
			}).then(res => {
				console.log(res)
				this.list = res.data.result.data;
				this.totalCostPrice = res.data.totalCostPrice;
			})

		},
		methods: {
			formatTimestamp(timestamp) {
				// 创建 Date 对象
				const date = new Date(timestamp * 1000); // 将时间戳转换为毫秒

				// 获取年份、月份、日期、小时、分钟、秒
				const year = date.getFullYear();
				const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始，需要加1
				const day = String(date.getDate()).padStart(2, '0');
				const hour = String(date.getHours()).padStart(2, '0');
				const minute = String(date.getMinutes()).padStart(2, '0');
				const second = String(date.getSeconds()).padStart(2, '0');

				// 返回格式化的日期时间字符串
				return `${year}-${month}-${day} ${year}:${minute}:${second}`;
			},
		}
	}
</script>

<style scoped lang="scss">
	.box {
		background-color: #2DBC26;
		display: flex;
		flex-direction: column;
		align-items: center;
		padding: 40rpx;
		justify-content: center;
		color: white;
		border-radius: 30rpx;
	}

	.items {
		background-color: white;
		border-radius: 30rpx;
		padding: 30rpx 20rpx;
		margin-top: 30rpx;

		.item {
			display: flex;
			padding: 20rpx;
			align-items: center;
			border-bottom: 1rpx solid #F4F4F4;

			.img-box {
				box-shadow: 0rpx 8rpx 10rpx rgba(152, 227, 125, 0.6);
				border-radius: 20rpx;
				width: 80rpx;
				height: 80rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				margin-right: 30rpx;
			}

			image {
				width: 40rpx;
				height: 40rpx;
			}
		}
	}
</style>